//package com.juzipi.demo.service;
//
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
//import com.juzipi.demo.mapper.UsersMapper;
//import com.juzipi.demo.pojo.Users;
//import org.apache.commons.lang3.StringUtils;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.security.core.GrantedAuthority;
//import org.springframework.security.core.authority.AuthorityUtils;
//import org.springframework.security.core.userdetails.User;
//import org.springframework.security.core.userdetails.UserDetails;
//import org.springframework.security.core.userdetails.UserDetailsService;
//import org.springframework.security.core.userdetails.UsernameNotFoundException;
//import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
//import org.springframework.stereotype.Service;
//
//import java.util.List;
//
//
//@Service
//public class MyUserDetailsService implements UserDetailsService {
//
//
//    @Autowired
//    private UsersMapper usersMapper;
//
//
//    @Override
//    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
//        if (StringUtils.isBlank(username)){
//            throw new UsernameNotFoundException("Bad_Request!");
//        }
//        QueryWrapper<Users> wrapper = new QueryWrapper<>();
//        wrapper.eq("username",username);
//        //查询用户
//        Users users = usersMapper.selectOne(wrapper);
//
//        //判断
//        if (StringUtils.isBlank(users.getUsername()) && StringUtils.isBlank(users.getPassword())){
//            throw new UsernameNotFoundException("NOT_FOUND!");
//        }
//
//        //在这里把返回的user对象设置权限
//        List<GrantedAuthority> role = AuthorityUtils.commaSeparatedStringToAuthorityList("admins,manager");
//        //查询数据库返回users对象，得到用户名和密码
//        return new User(username,new BCryptPasswordEncoder().encode(users.getPassword()),role);
//    }
//
//
//}
